// store/module/user.ts
import { Module } from 'vuex'
import { RootState } from '../index'
import { UserState } from '../../types/userType.ts'

export const user: Module<UserState, RootState> = {
    namespaced: true,
    state: {
        id: 0,
        username: "",
        avatar: "",
        gender: 0,
        email: "",
        phone: "",
        is_active: false,
        is_admin: false,
        is_superuser: false,
        is_ban: false,
        is_deleted: false,
        created_at: "",
        update_at: "",
        deleted_at: "",
    },
    mutations: {
        setUserData(state, userData) {
            state.id = userData.id;
            state.username = userData.username;
            state.avatar = userData.avatar_url;
            state.gender = userData.is_gender;
            state.is_active = userData.is_active;
            state.is_admin = userData.is_admin;
            state.is_superuser = userData.is_superuser;
            state.is_deleted = userData.is_deleted;
            state.email = userData.email;
            state.phone = userData.iphone;
            state.is_ban = userData.is_banned;
            state.created_at = userData.created_at;
            state.update_at = userData.updated_at;
            state.deleted_at = userData.deleted_at;
        },
    },
    actions: {
        setUserData({ commit }, userData) {
            commit('setUserData', userData);
        },
    },
};

export default user;
export type UserMutations = typeof user.mutations;  // 导出 mutations 类型
export type UserActions = typeof user.actions;      // 导出 actions 类型
